package com.example.myapplication.video.video_sift;


import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.mvp.mvp.view.BaseFragment;
import com.example.myapplication.R;
import com.example.myapplication.b_entity.Daxia;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public  class SiftVideoFragment extends BaseFragment<Vido_Presenter> implements Vido_Contract.Vido_View, LinerLayout_Test.OnScrollItemListener {


    //播放器适配器
    private Video_Adapter adapter;
    private LinerLayout_Test linerLayout_test;


    //页数
    private int page = 1;
    private RecyclerView fragVideo;
    private int index;
    private RecyclerView fragVideoRec;
    private Vido_Dianzan vidoDianzan;


    @Override
    public int findlayout() {
        return R.layout.fragment_sift_video;
    }

    @Override
    public void initView() {

        fragVideo = (RecyclerView) findViewById(R.id.frag_video_rec);

        linerLayout_test = new LinerLayout_Test(getContext());
        linerLayout_test.setOnScrollItemListener(this);
        fragVideo.setLayoutManager(linerLayout_test);

        fragVideoRec = (RecyclerView) findViewById(R.id.frag_video_rec);
        vidoDianzan = (Vido_Dianzan) findViewById(R.id.vido_dianzan);
    }

    @Override
    public void initData() {
        mypre = new Vido_Presenter(new Vido_Model(), this);
        mypre.getVido();
    }

    @Override
    public int getpagr() {
        return page;
    }

    @Override
    public void initAdapter(List<Daxia.DataBean> list) {
        if (adapter == null) {

            adapter = new Video_Adapter(list);

            fragVideo.setAdapter(adapter);
        } else {
            adapter.getData().addAll(list);
            adapter.notifyDataSetChanged();
        }

    }


    @Override
    public void selected(int postion, boolean isLoadMore) {
        index = postion;
        if (adapter != null) {
            adapter.play(fragVideo, postion);
        }
    }

    @Override
    public void release(int postion) {

    }

    @Override
    public void init(int postion) {
        if (adapter != null) {
            adapter.play(fragVideo, postion);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i("ljl", "onDestroy: ");
        if (adapter!=null){
            adapter.release(fragVideo,index);
        }
    }
}
